<?php

include_once("core/controller.php");
include_once("core/libs/configFile.php");
include_once("core/versionHandler.php");
/**
 * This Controller is used to activate/desactivate maintenance for an action
 * @copyright inovia
 * @package oolime_manager
 *
 */
class editMaintenance extends Controller {
   
	// only for manager group
	function isLegitimate(){
		global $configDispatcher;
    // Inputs verifications
    if(!$this->request->exist(Array("name"))){
      return false;
    }
    
    $tabVerify = Array(
	    "name"  => Array("string","Please enter an action name")
	  );
	  if( !$this->request->check($tabVerify)){
      $this->response->addError("Error in the name of the action","name");
      return false;
    }
    
    if(!isset($configDispatcher[$this->request->get('name')])){
      $this->response->addError("This action does not exist","name");
      return false;
    }
    
    return true;
	}

	function actions(){
		global $configDispatcher;
		$conf = new ConfigFile('actions.php');

		/* Switch the maintenance state and create xml for maintenance */

		// switch the maintenance state to false
  	if((int) $configDispatcher[$this->request->get('name')][3] == 1){
  	  $configDispatcher[$this->request->get('name')][3] = 0;
  	
	    if(! $conf->setVar("\$configDispatcher",$configDispatcher,true)){
	      $this->response->addError('Maintenance state for action '.$this->request->get('name').' failed','Maintenance');
	    }

		// switch the maintenance state to true
		}else {
  	  $configDispatcher[$this->request->get('name')][3] = 1;
  	
	    if(! $conf->setVar("\$configDispatcher",$configDispatcher,true)){
	      $this->response->addError('Maintenance state for action '.$this->request->get('name').' failed','Maintenance');
	    }
		}

		/* Launch homeMaintenance*/
		include('controls/manager/homeMaintenance.php');
		$this->response->setXSLT('views/manager/homeMaintenance.xsl');
		new HomeMaintenance();
  }

	function defaultActions(){
		include('controls/manager/homeMaintenance.php');
		$this->response->setXSLT('views/manager/homeMaintenance.xsl');
		new HomeMaintenance();
  }
}



?>
